//
//  RXTopView.swift
//  weibo
//
//  Created by uncle-R on 15/12/20.
//  Copyright © 2015年 uncle-R. All rights reserved.
//

import UIKit
import SDWebImage


class RXTopView: UIView {
    
    //顶部视图需要的模型
    var status: RXStatus? {
        didSet {
            
            //显示头像
            if let profile_image_url = status?.user?.profile_image_url {
                let url = NSURL(string: profile_image_url)!
                iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar"))
            }
            // 2.用户名称
            // nameLabel.text 是一个选
            nameLabel.text = status?.user?.screen_name
            
            // 3.时间
            timeLabel.text = "刚刚"
            
            // 4.来源
            sourceLabel.text = "火星"
              vipView.image = status?.user?.mbrankImage
            verifiedView.image = status?.user?.verifiedImage
 
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //修改颜色
        self.backgroundColor = UIColor.whiteColor()
        //准备UI
        prepareUI()
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    ///准备UI
   private func prepareUI(){
    
    //添加子控件
    addSubview(iconView)
    addSubview(nameLabel)
    addSubview(timeLabel)
    addSubview(sourceLabel)
    addSubview(vipView)
    addSubview(verifiedView)
    
    //2. 添加约束
    iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
    
    // 名称
    nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
    
    // 时间
    timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
    
    // 来源
    sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
    
    // 会员等级
    vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
    
    // 认证图标
    verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))

    
    
    
    }
   //MARK: - 懒加载控件
    
    ///用户头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))
    
    //用户名称
    private lazy var nameLabel:UILabel = {
        let label = UILabel()
        
        //设置字体颜色
        label.textColor = UIColor.darkGrayColor()
        
        label.font = UIFont.systemFontOfSize(14)
        
        return label
        
    }()
    
    ///微博时间
    private lazy var timeLabel: UILabel = {
        // 设置字体颜色
        let label = UILabel()
        label.textColor = UIColor.orangeColor()
        
        // 设置大小
        label.font = UIFont.systemFontOfSize(9)
        
        return label
    }()
    
    
    /// 微博来源
    private lazy var sourceLabel: UILabel = {
        let label = UILabel()
        
        // 设置字体颜色
        label.textColor = UIColor.lightGrayColor()
        
        // 设置大小
        label.font = UIFont.systemFontOfSize(9)
        
        return label
    }()
    
    /// 会员等级
    private lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    
    /// 认证图标
    private lazy var verifiedView: UIImageView = UIImageView(image: nil)

}
